﻿package net.wangit.view.report;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import net.sf.jasperreports.engine.JRAbstractExporter;
import net.sf.jasperreports.engine.JRExporterParameter;
import net.sf.jasperreports.engine.export.JRHtmlExporter;
import net.sf.jasperreports.engine.export.JRHtmlExporterParameter;
import net.wangit.context.LocalContext;
import net.wangit.framework.util.ResponseWriter;


public class HtmlReportExporter
	implements ReportExporter
{

	public HtmlReportExporter()
	{
	}

	public JRAbstractExporter createExporter()
	{
		return new JRHtmlExporter();
	}

	public void export(JRAbstractExporter exporter, HttpServletResponse response)
		throws Exception
	{
		StringBuffer writer = new StringBuffer();
		exporter.setParameter(JRExporterParameter.OUTPUT_STRING_BUFFER, writer);
		HttpSession session = LocalContext.getLocalContext().getHttpServletRequest().getSession();
		session.setAttribute("net.sf.jasperreports.j2ee.jasper_print", exporter.getParameter(JRExporterParameter.JASPER_PRINT));
		exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "/image?image=");
		exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, Boolean.FALSE);
		exporter.exportReport();
		ResponseWriter.write(response, writer.toString());
	}
}
